<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/11/12
 * Time: 10:20
 */

namespace app\adminapiv3\controller;

use think\facade\Request;
use think\facade\Validate;

class NormalRuleGroup extends Base
{
    /**
     * @name 官方规则组列表
     * @param $host_id
     * @author wx
     * @date 2019/11/12 13:14
     */
    public function list($host_id)
    {
        $params['name'] = $this->filterInput('name', 'get');
        $params['description'] = $this->filterInput('description', 'get');
        $params['status'] = $this->filterInput('status', 'get');

        $server = new \app\adminapiv3\service\NormalRuleGroup();
        $list = $server->toDo('list',[$host_id, $params, $this->getLimit()]);

        $this->jsonOutPut($list);
    }

    /**
     * @name 启用
     * @param $host_id
     * @author wx
     * @date 2019/11/12 14:22
     */
    public function open($host_id)
    {
        global $logContent;
        $logContent = '启用官方策略组';

        $id = $this->filterInput('id*', 'post');
        $params['status'] = $this->filterInput('status*', 'post');

        $server = new \app\adminapiv3\service\NormalRuleGroup();
        $server->modify($host_id, $id, $params);

        $this->jsonOutPut([],true);

        $this->Async('Wipf', 'WipfRules');
    }

    /**
     * @name 停用
     * @param $host_id
     * @author wx
     * @date 2019/11/12 14:28
     */
    public function close($host_id)
    {
        global $logContent;
        $logContent = '停用官方策略组';

        $id = $this->filterInput('id*', 'post');
        $params['status'] = $this->filterInput('status*', 'post');

        $server = new \app\adminapiv3\service\NormalRuleGroup();
        $server->modify($host_id, $id, $params);

        $this->jsonOutPut([],true);

        $this->Async('Wipf', 'WipfRules');
    }


        /**
     * @name: 修改处理方式
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-09-27 17:13:36
     */
    public function modifyHandle ($host_id)
    {
        global $logContent;
        $logContent = '修改策略组处理方式';
        $input = Request::only(['host_id','group_id','handle','status'], 'post');
        $validate = Validate::make([
            'host_id' => 'require|number',
            'group_id' => 'require|number',
            'handle' => 'require|in:0,1,2',
            'status' => 'require|in:0,1'
        ]);

        if (!$validate->check($input))
        {
            returnErrJson(422, $validate->getError());
        }

        $server = new \app\adminapiv3\service\NormalRuleGroup();
        $server->modifyHandle($input);

        $this->jsonOutPut([],true);

        $this->Async('Wipf', 'WipfRules');
    }

}